<template>
  <Layout>
    <div class="tags">
      <router-link class="tag" v-for="tag in tags"
                   :key="tag.id"
                   :to="`/labels/edit/${tag.id}`">
        <span>{{tag.name}}</span>
        <Icon name="right"/>
      </router-link>
    </div>
    <div class="createTag-wrapper">
      <Button @click.native="createTag">新建标签</Button>
    </div>
  </Layout>
</template>

<script lang="ts">
  import Vue from 'vue';
  import {Component} from 'vue-property-decorator';
  import Button from "@/components/Button.vue";
  import {mixins} from "vue-class-component";
  import TagHelper from "@/mixins/TagHelper";
  // import tagHelper from "@/mixins/tagHelper";  //ts中导入js对象会报错
  const tagHelper: any = require("@/mixins/TagHelper"); //如此解决就好
  //any的意思是tagHelper我就是从js里面拿到的 但是我现在没法知道它的类型 就暂定any把

  @Component({
    components: {Button},
    mixins:[tagHelper],
  })
  export default class Labels extends mixins(TagHelper) {
    get tags(){
        return this.$store.state.tagList
    }
      beforeCreate() {
          this.$store.commit('fetchTags');
      }

    // createTag() {
    //   const name=window.prompt('请输入标签名')
    //   if(!name){return window.alert('标签名不能为空')}
    //   this.$store.commit('createTag',name)
    // }  //用mixins替代
  }
</script>

<style lang="scss" scoped>
  .tags {
    background: #fff;
    font-size: 16px;
    padding-left: 16px;

    > .tag {
      min-height: 44px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #e6e6e6;

      svg {
        width: 15px;
        height: 15px;
        color: #c1c1c1;
        margin-right: 16px;
      }
    }
  }  .createTag-wrapper {
       text-align: center;
       padding: 16px;
       margin-top: 44-16px;
     }

</style>
